/**
 * Copyright (C) 2016-2019 DSpot Sp. z o.o
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dspot.declex.override.handler;

import java.util.Map;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;

import org.ohosannotations.OhosAnnotationsEnvironment;
import org.ohosannotations.ElementValidation;
import org.ohosannotations.annotations.FocusChange;
import org.ohosannotations.holder.EComponentWithViewSupportHolder;

import com.dspot.declex.holder.ViewsHolder;
import com.dspot.declex.holder.view_listener.FocusChangeHolder;
import com.dspot.declex.holder.view_listener.ViewListenerHolder;
import com.helger.jcodemodel.AbstractJClass;
import com.helger.jcodemodel.IJExpression;

/**
 * 焦点改变处理程序
 *
 * @author ohos
 * @date 2021/07/27
 */
public class FocusChangeHandler extends BaseViewListenerHandler {
	/**
	 * 焦点改变处理程序
	 *
	 * @param environment 环境
	 */
	public FocusChangeHandler(OhosAnnotationsEnvironment environment) {
		super(FocusChange.class, environment);
	}

	/**
	 * 验证
	 *
	 * @param element 元素
	 * @param valid 有效的
	 */
	@Override
	public void validate(Element element, ElementValidation valid) {
		super.validate(element, valid);
		
		if (element instanceof ExecutableElement) {
			ExecutableElement executableElement = (ExecutableElement) element;
			validatorHelper.returnTypeIsVoid(executableElement, valid);
		}
	}

	/**
	 * 让听众持有人
	 *
	 * @param elementName 元素名称
	 * @param elementClass 元素类
	 * @param declForListener decl为侦听器
	 * @param element 元素
	 * @param viewsHolder 观点持有者
	 * @param holder 持有人
	 * @return {@link ViewListenerHolder}
	 */
	@Override
	protected ViewListenerHolder getListenerHolder(String elementName,
			String elementClass, Map<AbstractJClass, IJExpression> declForListener,
			Element element, ViewsHolder viewsHolder, EComponentWithViewSupportHolder holder) {
		return holder.getPluginHolder(new FocusChangeHolder(holder));
	}
}
